package com.sxbbc.common.core.enums;

import com.sxbbc.common.basics.utils.calculation.CalcuUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * 商品类型枚举类
 * 与订单枚举类{@link OrderTypeEnums}保持一致
 * 本版本中未启用的商品类型，请将valid设置为false
 * type根据店铺类型控制显示的商品类型，与{@link BusinessTypeEnums}一致
 * @author leehao
 * @date 2019-05-27
 */
public enum ProductTypeEnums {
	NORMAL(1,"普通商品",true,null);

	private Integer id;

    private String name;

    private boolean valid;

    private Integer type;

    public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public boolean isValid() {
		return valid;
	}

	public void setValid(boolean valid) {
		this.valid = valid;
	}

	public Integer getType() {
		return type;
	}

	public void setType(Integer type) {
		this.type = type;
	}

	private ProductTypeEnums(Integer id, String name, boolean valid, Integer type){
		this.id=id;
		this.name=name;
		this.valid=valid;
		this.type=type;
	}

	/**
	 * 查询本版本有效的商品类型
	 * 根据商家类型查询
	 * @return
	 */
	public static List<ProductTypeEnums> queryValidList(Integer bType){
		List<ProductTypeEnums> list=new ArrayList<ProductTypeEnums>();
		for(ProductTypeEnums o: ProductTypeEnums.values()){
			if (o.isValid()) {
				if (CalcuUtils.getInstance().
						isEquals(o.getType(),bType) || o.getType() == null) {
					list.add(o);
				}
			}
		}
		return list;
	}

	public static String getName(Integer id){
		String str="";
		for(ProductTypeEnums o: ProductTypeEnums.values()){
			if(CalcuUtils.getInstance().isEquals(id, o.getId())){
				str= o.getName();
				break;
			}
		}
		return str;
	}
	
}
